package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/menus")
@Slf4j
public class MenusController {



    @Reference
    private MenusService menusService;
    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){

        PageResult pageResult =  menusService.findByPage(queryPageBean);

        return new Result(true, "查询分页成功",pageResult);
    }

    @RequestMapping("/delById")
    public Result delById(Integer id){

        menusService.delById(id);
        return new Result(true,"删除菜单信息成功");
    }


    @RequestMapping("/findById")
    public Result findById(Integer id) {

        Menu menu =  menusService.findById(id);
        return new Result(true, "查询菜单信息成功",menu);
    }


    @RequestMapping("/add")
    public Result add(@RequestBody Menu menu){

        menusService.add(menu);
        return new Result(true,"添加菜单信息成功");
    }
    @RequestMapping("/edit")
    public Result edit(@RequestBody Menu menu){

        menusService.edit(menu);
        return new Result(true,"修改菜单信息成功");

    }



}
